package com.xuanzuo.birthday.helper;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;

import com.xuanzuo.birthday.model.Friend;

public class FriendSqliteHelper extends SqliteHelper{
	
    //用来保存UserID、Access Token、Access Secret的表名	
    public static String TB_NAME = "xz_bd_friends";
    public FriendSqliteHelper(Context context, String name, CursorFactory factory, int version) {
        super(context, name, factory, version);
    }
    
    //创建表
    @Override
    public void onCreate(SQLiteDatabase db) {
    	String sql = "CREATE TABLE IF NOT EXISTS " + TB_NAME + "(" +
                Friend.ID+" integer primary key,"+
                Friend.FRIENDID+" varchar,"+
                Friend.FRIENDNAME+" varchar,"+
                Friend.ICON+" blob,"+
                Friend.MEDIATYPE+" varchar,"+
                Friend.STATUS+" varchar,"+
                Friend.BIRTHDAY+" varchar,"+
                Friend.WISHES+" varchar,"+
                Friend.ALARMTIME+" varchar,"+
                Friend.ALARMTYPE+" varchar"+
                ")" ;
        db.execSQL(sql);
        Log.e("Database","onCreate");
    }
    
    //更新表
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TB_NAME);
        onCreate(db);
        Log.e("Database","onUpgrade");
    }
    
    //更新列
    public void updateColumn(SQLiteDatabase db, String oldColumn, String newColumn, String typeColumn){
        try{
            db.execSQL("ALTER TABLE " +
                    TB_NAME + " CHANGE " +
                    oldColumn + " "+ newColumn +
                    " " + typeColumn
            );
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
